package com.jugheadzhou.core.message.rabbitmq.consumer.handler;

import com.jugheadzhou.core.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
import org.springframework.amqp.rabbit.listener.api.RabbitListenerErrorHandler;
import org.springframework.amqp.rabbit.support.ListenerExecutionFailedException;

/**
 * @author jugheadzhou
 * @date 2021-12-03
 */
@Slf4j
public class ReceiverListenerDefaultErrorHandler implements RabbitListenerErrorHandler {

    @Override
    public Object handleError(org.springframework.amqp.core.Message message,
                              org.springframework.messaging.Message<?> message1,
                              ListenerExecutionFailedException e) {
        log.error("消息接收发生了错误，消息内容:{}",
                JsonUtil.object2String(message.getBody()), e);
        throw new AmqpRejectAndDontRequeueException("消息接收发生了未知错误，停止接收并等待重启后重新入队");
    }
}

